<template>
  <el-dialog
    v-dialogDrag
    v-loading="loading"
    :visible="visible"
    :title="title"
    width="1000px"
    class="knowledge-dialog"
    :close-on-click-modal="false"
    :before-close="close"
    @close="onClose"
    @open="onOpen"
  >
    <network-chart :data="data" height="600px" />
  </el-dialog>
</template>

<script>
import NetworkChart from '@/components/NetworkChart/index'
import { getRelationNetwork } from '@/api/fmea/common/structureTree'
export default {
  name: 'NetworkDialog',
  components: { NetworkChart },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    params: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      loading: false,
      data: null,
      title: '',
      nodeType: this.$store.state.fmea.nodeType
    }
  },
  methods: {
    // 窗口打开
    onOpen() {
      if ([this.nodeType.function.value, this.nodeType.character.value].includes(this.params.nodeType)) {
        this.title = this.$t('functionAnalysis.functionalNetwork')
      } else {
        this.title = this.$t('failureAnalysis.failureNetwork')
      }
      this.loading = true
      getRelationNetwork(this.params).then(res => {
        this.loading = false
        if (res.data) {
          this.data = res.data
        } else {
          this.$message.error(this.$t('structureAnalysis.incompleteData'))
        }
      })
    },
    // 窗口关闭
    onClose() {
      this.data = null
    },
    // 窗口关闭前执行
    close() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped>

</style>
